package com.jiaquyun.jcyx.main.goods

import android.app.Activity
import android.content.Intent
import android.view.View
import android.view.inputmethod.EditorInfo
import com.blankj.utilcode.util.FragmentUtils
import com.jiaquyun.jcyx.R
import com.module.lemlin.owner.OwnerAbstractActivity
import kotlinx.android.synthetic.main.activity_goods_search.*

class GoodsSearchActivity : OwnerAbstractActivity() {

    companion object {
        fun open(activity: Activity) {
            val intent = Intent(activity, GoodsSearchActivity::class.java)
            activity.startActivity(intent)
        }
    }

    override val layoutResId: Int
        get() = R.layout.activity_goods_search

    override fun stateBar(): StatusBar {
        return StatusBar(isLightMode = true, view = flGoodsSearchBar)
    }

    override fun initView() {
        tvGoodsSearchClose.setOnClickListener {
            this.finish()
        }

        etGoodsSearchContent.setOnEditorActionListener { v, actionId, event ->
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                val content: String = etGoodsSearchContent.text.toString()
                if (content.isEmpty()) {
                    return@setOnEditorActionListener true
                }
                FragmentUtils.replace(
                    supportFragmentManager,
                    GoodsScreenFragment.newInstance(content),
                    R.id.flGoodsSearchBody, (true),
                    R.animator.slide_right_in,
                    R.animator.slide_left_out,
                    R.animator.slide_left_in,
                    R.animator.slide_right_out
                )
                return@setOnEditorActionListener true
            }
            return@setOnEditorActionListener false
        }

        FragmentUtils.add(
            supportFragmentManager,
            GoodsRecordFragment.newInstance(),
            R.id.flGoodsSearchBody
        )

    }

    fun onClick(view: View) {

    }
}